package com.warehouseprovider.service;

import com.warehouseprovider.dao.UserMapper;
import entity.ResponseMessage;
import entity.StatusCode;
import entity.User;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Service;
import service.ZUserService;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Service
public class ZUserServiceImpl implements ZUserService {
    private Logger logger=Logger.getLogger(this.getClass());

    @Resource
    private UserMapper userMapper;

    /**
     * 查询仓管人员
     * @return
     */
    @Override
    public ResponseMessage getQueryWarehouse() {
        logger.info("ZUserServiceImpl getQueryWarehouse is start......");
        List<User> list=new ArrayList<>();
        ResponseMessage msg=new ResponseMessage();
        try {
            list=userMapper.getQueryWarehouse();
            if(list==null){
                logger.error("ZUserServiceImpl getQueryWarehouse is error;param:"+list);
                msg.setFlag(false);
                msg.setCode(StatusCode.ERROR);
                msg.setMessage("查询仓管人员失败！");
                return msg;
            }
        }catch (Exception e){
            e.printStackTrace();
            logger.info("ZUserServiceImpl getQueryWarehouse is error",e);
            msg.setCode(StatusCode.ERROR);
            msg.setMessage("进入异常出错！");
            msg.setFlag(false);
            return msg;
        }
        logger.debug("ZUserServiceImpl getQueryWarehouse is success,result:"+list);
        msg.setCode(StatusCode.OK);
        msg.setFlag(true);
        msg.setMessage("查询仓管人员成功！");
        msg.setData(list);
        return msg;
    }
}
